﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YiLe.UI
{
    public partial class CustomerDataControl : DataControl
    {
        protected override void OnDataSourceChanged()
        {
            this.AddBinding(this.editCompanyName, "Text", "Customers.CompanyName");
            this.AddBinding(this.editContactName, "Text", "Customers.ContactName");
            this.AddBinding(this.editContactTitle, "Text", "Customers.ContactTitle");
            this.AddBinding(this.editCustomerId, "Text", "Customers.CustomerID");
            this.AddBinding(this.editAddress, "Text", "Customers.Address");
            this.AddBinding(this.editCity, "Text", "Customers.City");
            this.AddBinding(this.editCountry, "Text", "Customers.Country");
            this.AddBinding(this.editFax, "Text", "Customers.Fax");
            this.AddBinding(this.editPhone, "Text", "Customers.Phone");
            this.AddBinding(this.editPostalCode, "Text", "Customers.PostalCode");
            this.AddBinding(this.editRegion, "Text", "Customers.Region");

        }

        protected override void OnAllowEditChanged()
        {
            /* TODO:this.AllowEdit*/
            this.editCustomerId.ReadOnly = (!this.AllowEdit) | (!this.IsAddNew);

            this.editCompanyName.ReadOnly = !this.AllowEdit;
            this.editContactName.ReadOnly = !this.AllowEdit;
            this.editContactTitle.ReadOnly = !this.AllowEdit;
            this.editAddress.ReadOnly = !this.AllowEdit;
            this.editCity.ReadOnly = !this.AllowEdit;
            this.editCountry.ReadOnly = !this.AllowEdit;
            this.editFax.ReadOnly = !this.AllowEdit;
            this.editPhone.ReadOnly = !this.AllowEdit;
            this.editPostalCode.ReadOnly = !this.AllowEdit;
            this.editRegion.ReadOnly = !this.AllowEdit;
        }

        protected override void OnIsAddNewChanged()
        {
            this.editCustomerId.ReadOnly = !this.IsAddNew;
        }

        public override Size FullSize
        {
            get
            {
                return new System.Drawing.Size(572, 240);
            }
        }

        protected override void OnUseTabBackgroundChanged()
        {
            if (this.UseTabBackground)
            {
                this.gbBackground.BackgroundStyle = Janus.Windows.EditControls.BackgroundStyle.TabPage;
            }
            else
            {
                this.gbBackground.BackgroundStyle = Janus.Windows.EditControls.BackgroundStyle.Panel;
            }
        }
    }
}
